﻿using EFCore.Models;
using Microsoft.EntityFrameworkCore;
using SIService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SService
{
    public class InventorydetailsS : InventorydetailsSI
    {
        private readonly WmssystemContext myDb;

        public InventorydetailsS(WmssystemContext myDb)
        {
            this.myDb = myDb;
        }

        public async Task<int> Add(PO_Inventorydetails pO_Inventorydetails)
        {
            pO_Inventorydetails.I_IProductionDate = DateTime.Now;
            myDb.PO_Inventorydetails.Add(pO_Inventorydetails); // 确保不显式指定标识列的值
            return await myDb.SaveChangesAsync();
        }

        public Task<int> Del(int id)
        {
            var pp = myDb.PO_Inventorydetails.SingleOrDefault(e => e.I_IIndex == id);
            myDb.PO_Inventorydetails.Remove(pp);
            return myDb.SaveChangesAsync();
        }

        public Task<List<PO_Inventorydetails>> Qu()
        {
            return myDb.PO_Inventorydetails.OrderByDescending(p => p.I_IIndex).ToListAsync();
        }
    }
}
